// $ANTLR 2.7.6 (20061021): "iCal.g" -> "iCalLexer.cs"$


namespace DDay.iCal
{
	using BitSet = antlr.collections.impl.BitSet;
	using ByteBuffer = antlr.ByteBuffer;
	using CharBuffer = antlr.CharBuffer;
	using CharStreamException = antlr.CharStreamException;
	using CharStreamIOException = antlr.CharStreamIOException;
	using Comparer = System.Collections.Comparer;
	using Hashtable = System.Collections.Hashtable;
	using InputBuffer = antlr.InputBuffer;
	using IToken = antlr.IToken;
	using LexerSharedInputState = antlr.LexerSharedInputState;
	using NoViableAltForCharException = antlr.NoViableAltForCharException;
	using RecognitionException = antlr.RecognitionException;
	// Generate header specific to lexer CSharp file
	using Stream = System.IO.Stream;
	using TextReader = System.IO.TextReader;
	using Token = antlr.Token;
	using TokenStream = antlr.TokenStream;
	using TokenStreamException = antlr.TokenStreamException;
	using TokenStreamIOException = antlr.TokenStreamIOException;
	using TokenStreamRecognitionException = antlr.TokenStreamRecognitionException;

	public class iCalLexer : antlr.CharScanner, TokenStream
	{
		public const int EOF = 1;
		public const int NULL_TREE_LOOKAHEAD = 3;
		public const int CRLF = 4;
		public const int BEGIN = 5;
		public const int COLON = 6;
		public const int VCALENDAR = 7;
		public const int END = 8;
		public const int IANA_TOKEN = 9;
		public const int X_NAME = 10;
		public const int SEMICOLON = 11;
		public const int EQUAL = 12;
		public const int COMMA = 13;
		public const int DQUOTE = 14;
		public const int CTL = 15;
		public const int BACKSLASH = 16;
		public const int NUMBER = 17;
		public const int DOT = 18;
		public const int CR = 19;
		public const int LF = 20;
		public const int ALPHA = 21;
		public const int DIGIT = 22;
		public const int DASH = 23;
		public const int UNDERSCORE = 24;
		public const int UNICODE = 25;
		public const int SPECIAL = 26;
		public const int SPACE = 27;
		public const int HTAB = 28;
		public const int SLASH = 29;
		public const int ESCAPED_CHAR = 30;
		public const int LINEFOLDER = 31;

		public iCalLexer(Stream ins)
			: this(new ByteBuffer(ins))
		{
		}

		public iCalLexer(TextReader r)
			: this(new CharBuffer(r))
		{
		}

		public iCalLexer(InputBuffer ib)
			: this(new LexerSharedInputState(ib))
		{
		}

		public iCalLexer(LexerSharedInputState state)
			: base(state)
		{
			initialize();
		}
		private void initialize()
		{
			caseSensitiveLiterals = true;
			setCaseSensitive(true);
			literals = new Hashtable(100, (float)0.4, null, Comparer.Default);
		}

		override public IToken nextToken()			//throws TokenStreamException
		{
			IToken theRetToken = null;
		tryAgain:
			for (; ; )
			{
				//IToken _token = null;
				int _ttype = Token.INVALID_TYPE;
				resetText();
				try     // for char stream error handling
				{
					try     // for lexical error handling
					{
						switch (cached_LA1)
						{
							case '\n':
								{
									mLF(true);
									theRetToken = returnToken_;
									break;
								}
							case ' ':
								{
									mSPACE(true);
									theRetToken = returnToken_;
									break;
								}
							case '\t':
								{
									mHTAB(true);
									theRetToken = returnToken_;
									break;
								}
							case ':':
								{
									mCOLON(true);
									theRetToken = returnToken_;
									break;
								}
							case ';':
								{
									mSEMICOLON(true);
									theRetToken = returnToken_;
									break;
								}
							case ',':
								{
									mCOMMA(true);
									theRetToken = returnToken_;
									break;
								}
							case '.':
								{
									mDOT(true);
									theRetToken = returnToken_;
									break;
								}
							case '=':
								{
									mEQUAL(true);
									theRetToken = returnToken_;
									break;
								}
							case '/':
								{
									mSLASH(true);
									theRetToken = returnToken_;
									break;
								}
							case '"':
								{
									mDQUOTE(true);
									theRetToken = returnToken_;
									break;
								}
							default:
								if ((cached_LA1 == '\r') && (cached_LA2 == '\n') && (LA(3) == '\t' || LA(3) == ' '))
								{
									mLINEFOLDER(true);
									theRetToken = returnToken_;
								}
								else if ((cached_LA1 == '\r') && (cached_LA2 == '\n') && (true))
								{
									mCRLF(true);
									theRetToken = returnToken_;
								}
								else if ((cached_LA1 == '\\') && (tokenSet_0_.member(cached_LA2)))
								{
									mESCAPED_CHAR(true);
									theRetToken = returnToken_;
								}
								else if ((cached_LA1 == '\\') && (true))
								{
									mBACKSLASH(true);
									theRetToken = returnToken_;
								}
								else if ((tokenSet_1_.member(cached_LA1)) && (true))
								{
									mCTL(true);
									theRetToken = returnToken_;
								}
								else if ((tokenSet_2_.member(cached_LA1)))
								{
									mIANA_TOKEN(true);
									theRetToken = returnToken_;
								}
								else
								{
									if (cached_LA1 == EOF_CHAR) { uponEOF(); returnToken_ = makeToken(Token.EOF_TYPE); }
									else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn()); }
								}
								break;
						}
						if (null == returnToken_) goto tryAgain; // found SKIP token
						_ttype = returnToken_.Type;
						_ttype = testLiteralsTable(_ttype);
						returnToken_.Type = _ttype;
						return returnToken_;
					}
					catch (RecognitionException e)
					{
						throw new TokenStreamRecognitionException(e);
					}
				}
				catch (CharStreamException cse)
				{
					if (cse is CharStreamIOException)
					{
						throw new TokenStreamIOException(((CharStreamIOException)cse).io);
					}
					else
					{
						throw new TokenStreamException(cse.Message);
					}
				}
			}
		}

		protected void mCR(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = CR;

			match('\u000d');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mLF(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = LF;

			match('\u000a');
			_ttype = Token.SKIP;
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		protected void mALPHA(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = ALPHA;

			switch (cached_LA1)
			{
				case 'A':
				case 'B':
				case 'C':
				case 'D':
				case 'E':
				case 'F':
				case 'G':
				case 'H':
				case 'I':
				case 'J':
				case 'K':
				case 'L':
				case 'M':
				case 'N':
				case 'O':
				case 'P':
				case 'Q':
				case 'R':
				case 'S':
				case 'T':
				case 'U':
				case 'V':
				case 'W':
				case 'X':
				case 'Y':
				case 'Z':
					{
						matchRange('\u0041', '\u005a');
						break;
					}
				case 'a':
				case 'b':
				case 'c':
				case 'd':
				case 'e':
				case 'f':
				case 'g':
				case 'h':
				case 'i':
				case 'j':
				case 'k':
				case 'l':
				case 'm':
				case 'n':
				case 'o':
				case 'p':
				case 'q':
				case 'r':
				case 's':
				case 't':
				case 'u':
				case 'v':
				case 'w':
				case 'x':
				case 'y':
				case 'z':
					{
						matchRange('\u0061', '\u007a');
						break;
					}
				default:
					{
						throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());
					}
			}
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		protected void mDIGIT(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = DIGIT;

			matchRange('\u0030', '\u0039');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		protected void mDASH(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = DASH;

			match('\u002d');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		protected void mUNDERSCORE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = UNDERSCORE;

			match('\u005F');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		protected void mUNICODE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = UNICODE;

			matchRange('\u0100', '\uFFFE');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		protected void mSPECIAL(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = SPECIAL;

			switch (cached_LA1)
			{
				case '!':
					{
						match('\u0021');
						break;
					}
				case '#':
				case '$':
				case '%':
				case '&':
				case '\'':
				case '(':
				case ')':
				case '*':
				case '+':
					{
						matchRange('\u0023', '\u002b');
						break;
					}
				case '<':
					{
						match('\u003c');
						break;
					}
				case '>':
				case '?':
				case '@':
					{
						matchRange('\u003e', '\u0040');
						break;
					}
				case '[':
					{
						match('\u005b');
						break;
					}
				case ']':
				case '^':
					{
						matchRange('\u005d', '\u005e');
						break;
					}
				case '`':
					{
						match('\u0060');
						break;
					}
				case '{':
				case '|':
				case '}':
				case '~':
					{
						matchRange('\u007b', '\u007e');
						break;
					}
				default:
					if (((cached_LA1 >= '\u0080' && cached_LA1 <= '\u00ff')))
					{
						matchRange('\u0080', '\u00ff');
					}
					else
					{
						throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());
					}
					break;
			}
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mSPACE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = SPACE;

			match('\u0020');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mHTAB(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = HTAB;

			match('\u0009');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mCOLON(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = COLON;

			match('\u003a');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mSEMICOLON(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = SEMICOLON;

			match('\u003b');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mCOMMA(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = COMMA;

			match('\u002c');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mDOT(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = DOT;

			match('\u002e');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mEQUAL(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = EQUAL;

			match('\u003d');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mBACKSLASH(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = BACKSLASH;

			match('\u005c');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mSLASH(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = SLASH;

			match('\u002f');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mDQUOTE(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = DQUOTE;

			match('\u0022');
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mCRLF(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = CRLF;

			mCR(false);
			mLF(false);
			newline();
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mCTL(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = CTL;

			switch (cached_LA1)
			{
				case '\u0000':
				case '\u0001':
				case '\u0002':
				case '\u0003':
				case '\u0004':
				case '\u0005':
				case '\u0006':
				case '\u0007':
				case '\u0008':
					{
						matchRange('\u0000', '\u0008');
						break;
					}
				case '\u000b':
				case '\u000c':
				case '\r':
				case '\u000e':
				case '\u000f':
				case '\u0010':
				case '\u0011':
				case '\u0012':
				case '\u0013':
				case '\u0014':
				case '\u0015':
				case '\u0016':
				case '\u0017':
				case '\u0018':
				case '\u0019':
				case '\u001a':
				case '\u001b':
				case '\u001c':
				case '\u001d':
				case '\u001e':
				case '\u001f':
					{
						matchRange('\u000b', '\u001F');
						break;
					}
				case '\u007f':
					{
						match('\u007F');
						break;
					}
				default:
					{
						throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());
					}
			}
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mESCAPED_CHAR(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = ESCAPED_CHAR;

			mBACKSLASH(false);
			{
				switch (cached_LA1)
				{
					case '\\':
						{
							mBACKSLASH(false);
							break;
						}
					case '"':
						{
							mDQUOTE(false);
							break;
						}
					case ';':
						{
							mSEMICOLON(false);
							break;
						}
					case ',':
						{
							mCOMMA(false);
							break;
						}
					case 'N':
						{
							match("N");
							break;
						}
					case 'n':
						{
							match("n");
							break;
						}
					default:
						{
							throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());
						}
				}
			}
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mIANA_TOKEN(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = IANA_TOKEN;

			{ // ( ... )+
				int _cnt82 = 0;
				for (; ; )
				{
					switch (cached_LA1)
					{
						case 'A':
						case 'B':
						case 'C':
						case 'D':
						case 'E':
						case 'F':
						case 'G':
						case 'H':
						case 'I':
						case 'J':
						case 'K':
						case 'L':
						case 'M':
						case 'N':
						case 'O':
						case 'P':
						case 'Q':
						case 'R':
						case 'S':
						case 'T':
						case 'U':
						case 'V':
						case 'W':
						case 'X':
						case 'Y':
						case 'Z':
						case 'a':
						case 'b':
						case 'c':
						case 'd':
						case 'e':
						case 'f':
						case 'g':
						case 'h':
						case 'i':
						case 'j':
						case 'k':
						case 'l':
						case 'm':
						case 'n':
						case 'o':
						case 'p':
						case 'q':
						case 'r':
						case 's':
						case 't':
						case 'u':
						case 'v':
						case 'w':
						case 'x':
						case 'y':
						case 'z':
							{
								mALPHA(false);
								break;
							}
						case '0':
						case '1':
						case '2':
						case '3':
						case '4':
						case '5':
						case '6':
						case '7':
						case '8':
						case '9':
							{
								mDIGIT(false);
								break;
							}
						case '-':
							{
								mDASH(false);
								break;
							}
						case '_':
							{
								mUNDERSCORE(false);
								break;
							}
						default:
							if ((tokenSet_3_.member(cached_LA1)))
							{
								mSPECIAL(false);
							}
							else if (((cached_LA1 >= '\u0100' && cached_LA1 <= '\ufffe')))
							{
								mUNICODE(false);
							}
							else
							{
								if (_cnt82 >= 1) { goto _loop82_breakloop; } else { throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn()); ; }
							}
							break;
					}
					_cnt82++;
				}
			_loop82_breakloop: ;
			}    // ( ... )+

			string s = text.ToString(_begin, text.Length - _begin);
			int val;
			if (int.TryParse(s, out val))
				_ttype = NUMBER;
			else
			{
				switch (s.ToUpper())
				{
					case "BEGIN": _ttype = BEGIN; break;
					case "END": _ttype = END; break;
					case "VCALENDAR": _ttype = VCALENDAR; break;
					default:
						if (s.Length > 2 && s.Substring(0, 2).Equals("X-"))
							_ttype = X_NAME;
						break;
				}
			}

			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}

		public void mLINEFOLDER(bool _createToken) //throws RecognitionException, CharStreamException, TokenStreamException
		{
			int _ttype; IToken _token = null; int _begin = text.Length;
			_ttype = LINEFOLDER;

			mCRLF(false);
			{
				switch (cached_LA1)
				{
					case ' ':
						{
							mSPACE(false);
							break;
						}
					case '\t':
						{
							mHTAB(false);
							break;
						}
					default:
						{
							throw new NoViableAltForCharException(cached_LA1, getFilename(), getLine(), getColumn());
						}
				}
			}
			_ttype = Token.SKIP;
			if (_createToken && (null == _token) && (_ttype != Token.SKIP))
			{
				_token = makeToken(_ttype);
				_token.setText(text.ToString(_begin, text.Length - _begin));
			}
			returnToken_ = _token;
		}


		private static long[] mk_tokenSet_0_()
		{
			long[] data = new long[1025];
			data[0] = 576478361669337088L;
			data[1] = 70369012629504L;
			for (int i = 2; i <= 1024; i++) { data[i] = 0L; }
			return data;
		}
		public static readonly BitSet tokenSet_0_ = new BitSet(mk_tokenSet_0_());
		private static long[] mk_tokenSet_1_()
		{
			long[] data = new long[1025];
			data[0] = 4294965759L;
			data[1] = -9223372036854775808L;
			for (int i = 2; i <= 1024; i++) { data[i] = 0L; }
			return data;
		}
		public static readonly BitSet tokenSet_1_ = new BitSet(mk_tokenSet_1_());
		private static long[] mk_tokenSet_2_()
		{
			long[] data = new long[2560];
			data[0] = -3170762861857210368L;
			data[1] = 9223372036586340351L;
			for (int i = 2; i <= 1022; i++) { data[i] = -1L; }
			data[1023] = 9223372036854775807L;
			for (int i = 1024; i <= 2559; i++) { data[i] = 0L; }
			return data;
		}
		public static readonly BitSet tokenSet_2_ = new BitSet(mk_tokenSet_2_());
		private static long[] mk_tokenSet_3_()
		{
			long[] data = new long[1025];
			data[0] = -3458746947404300288L;
			data[1] = 8646911290591150081L;
			for (int i = 2; i <= 3; i++) { data[i] = -1L; }
			for (int i = 4; i <= 1024; i++) { data[i] = 0L; }
			return data;
		}
		public static readonly BitSet tokenSet_3_ = new BitSet(mk_tokenSet_3_());

	}
}
